(function () {
    var map = new BMapGL.Map('map');                // 创建地图实例 
    var point = new BMapGL.Point(126.693861, 45.792089);  // 创建点坐标 
    map.centerAndZoom(point, 17);                 // 初始化地图，设置中心点坐标和地图级别
    map.enableScrollWheelZoom(true);              //开启鼠标滚轮缩放
    var marker = new BMapGL.Marker(point);        // 创建标注   
    map.addOverlay(marker);                       // 将标注添加到地图中
    map.addEventListener("click", e => {
        var p = new BMapGL.Point(e.latlng.lng, e.latlng.lat);
        var m = new BMapGL.Marker(p);
        last = m
        map.addOverlay(m);                        // 将标注添加到地图中
    })
    var circle = new BMapGL.Circle(point, 50, { strokeColor: "pink", strokeWeight: 1, strokeOpacity: 0.5 }); //创建坐标圆
    map.addOverlay(circle);
})();


(function () {
    let upbtn = document.querySelector('.upbtn')
    let nameInput = document.querySelector('.name')
    let emailInput = document.querySelector('.message .email')
    let subjectInput = document.querySelector('.subject input')
    let commentInput = document.querySelector('.comment')
    upbtn.addEventListener('click', function () {
        if (nameInput.value.trim() == "") {
            nameInput.setAttribute('class', 'change')
            nameInput.setAttribute('placeholder', '请输入您的姓名')
        }
        if (emailInput.value.trim().indexOf('@') == -1) {
            emailInput.setAttribute('class', 'change')
            emailInput.setAttribute('placeholder', '邮箱必须包含@')
        }
        if (subjectInput.value.trim() == "") {
            subjectInput.setAttribute('class', 'change')
            subjectInput.setAttribute('placeholder', '请输入您的主题')
        }
        if (commentInput.value.trim() == "") {
            commentInput.setAttribute('class', 'change')
            commentInput.setAttribute('placeholder', '请输入您的内容')
        }
        else {
            post()
        }
    })
    function error(obj, message) {
        obj.setAttribute('class', 'change')
        obj.setAttribute('placeholder', message)
    }
    function post() {
        axios.post('http://81.70.162.221:3000/postComment', {
            name: nameInput.value,
            email: emailInput.value,
            content: commentInput.value,
            title: subjectInput.value
        }).then(function (res) {
            if (res.data == 'success') {
                alert("您的信息已提交,感谢您的留言")
            }
        })
    }
})();